import Flutter
import Foundation

class PigeonsConfig {
    // 负责调用 Flutter 的 API
    static var api: MessageFlutterApi?

    // 配置 FlutterEngine
    static func configureFlutterEngine(controller: FlutterViewController) {
        // 设置 HostApi
        MessageHostApiSetup.setUp(binaryMessenger: controller.binaryMessenger, api: AppMessageHostApi())
        // 初始化 FlutterApi
        api = MessageFlutterApi(binaryMessenger: controller.binaryMessenger)
    }

    // 调用 Flutter API
    static func apiCall(params: CommonParams, callback: @escaping (Result<CommonParams, PigeonError>) -> Void) {
        api?.call(params: params, completion: callback)
    }
}
